/**
 * @file:          StepController.h
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2023.07.20
 * @version:       1.0.0
 * @par copyright (c):
 *
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.07.20,19:45:01
 */

#ifndef _STEPCONTROLLER_H_
#define _STEPCONTROLLER_H_

/* Include Files **************************************************************/
#include "Datatype.h"
#include "common.h"
#include "DriverList.h"

/* Macro Definition ***********************************************************/

/* Data Type Define ***********************************************************/
typedef struct StepController
{
    /* public data */
    Mcu *mcu;

    uint16 param_pulse_count_max;
    uint16 param_subdivision;
    uint16 param_pulse_trim_en;
    uint16 param_trim_action_period;
    uint16 param_extra_trim_pulse;
    uint16 param_single_turn_mode;
    float32 step2rad;

    int32 pulse_count;
    int32 pulse_count_last;
    int32 step_increment;
    int32 step;
    int32 step_turns;
    int64 step_accumulate;
    int16 dir;
    uint16 dir_pin;
    uint16 dir_pin_last;
    uint16 en;
    int32 pulse_on_dir_change;
    uint16 dir_change;
    int32 pulse_trim;
    uint16 trim_action_count;
    uint32 steps_per_turn;

    float32 out_pos_cmd;
    int64 out_pulse_cmd;

    /* private data */

    /* public method */
    void (*Init)(struct StepController *self);
    float32 (*Run)(struct StepController *self);
    void (*UpdateParam)(struct StepController *self);
    void (*SetInitStepFromRad)(struct StepController *self, float rad);

    /* private method */

} StepController;

/* Variable Declare ***********************************************************/

/* Function Declare ***********************************************************/
void StepController_Init(struct StepController *self);
float32 StepController_Run(struct StepController *self);
void StepController_UpdateParam(struct StepController *self);
void StepController_SetInitStepFromRad(struct StepController *self, float rad);

#endif